package com.spring.sjlong.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.spring.sjlong.model.dto.UserDto;
import com.spring.sjlong.model.pojo.User;
import com.spring.sjlong.service.IUserService;
import com.spring.sjlong.util.ResultJsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("admin/user")
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Resource
    private IUserService userService;

    /**
     * 获取全部用户信息
     *
     * @return
     */
    @PostMapping("/getUserList")
    public JSONObject getUserList(@RequestBody UserDto userDto) {
        logger.info("用户查询参数：{}", JSON.toJSONString(userDto));
        List<User> userList = null;
        try{
            userList = userService.getUserList(userDto);
        }catch (Exception e){
            logger.error("失败原因：",e);
        }
        logger.info("全部用户信息：{}", JSONObject.toJSONString(userList));
        return ResultJsonUtil.convertResultJSONList("S", "获取用户信息成功", userList);
    }

}
